<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<style>
    .bootbox-close-button {
        width: 19px;
        height: 19px;
        border: none;
        cursor: pointer;
        -webkit-appearance: none;
        float: right;
        top: 4px;
        left: -5px;
        position: relative;
        background: #E9F5FF url("assets/img/nav-img/icon_close.png") no-repeat 0 0;
    }
    .tssSemesterEdit .modal-dialog {
        width: 60% !important;
    }

    .tssSemesterEdit .modal-body {
        padding-bottom: 0;
    }
    input,select{
        height: 30px!important;
        border-radius: 5px!important;
    }
</style>
<div class="col-lg-12 col-sm-12 col-xs-12">
    <div class="modal-header">
        <button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true">x</button>
        <h4 class="modal-title">${(editModel=='add')?string('新增学期','编辑学期')}</h4>
    </div>
    <div class="modal-body" style="padding-top: 0px!important">
        <div class="row">
            <form class="editForm" action="${saveUrl}" method="post" responseType="JSON" role="form"
                  id="editForm_${serializeNum}"
                  data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
                  data-bv-message="This value is not valid"
                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
                <input type="hidden" name="id" value="${editEntity.id}">

                <div class="col-xm-12 col-sm-12 col-lg-12 margin-top-20">
                    <div class="form-group">
                        <label class="col-xm-2 col-sm-2 col-lg-2 col-sm-offset-2 control-label no-padding-right"><span style="color: red">*</span>年份：</label>
                        <div class="col-xm-4 col-sm-4 col-lg-4">
                            <select
                                    data-bv-message="日期已在设置学期之间！"
                                    alt="年份"
                                    placeholder="年份"
                                    type="text" title="年份"
                                    class="form-select-1 form-control" id="newParticularYear" style="width: 200px;height: 30px;border: 1px solid #c6d5d8;border-radius: 4px !important;"
                                    name="particularYear" required="required" value="${editEntity.particularYear}">
                            </select>
                        </div>
                    </div>
                </div>

                <div class="col-xm-12 col-sm-12 col-lg-12">
                    <div class="form-group">
                        <label
                                class="col-xm-2 col-sm-2 col-lg-2 col-sm-offset-2 control-label no-padding-right"><span style="color: red">*</span>学期类型：</label>
                        <div class="col-xm-4 col-sm-4 col-lg-4">
                            <select class="form-select-1 form-control date-picker" style="width: 200px;height: 30px;border: 1px solid #c6d5d8;border-radius: 4px !important;"
                                    name="type" required="required"
                                    disabled="disabled"
                                    data-bv-message="日期已在设置学期之间！"
                                    required="required "
                                    alt="学期类型"
                                    placeholder="学期类型">
                                <option value="">请选择</option>
                                <@dictionary groupCode="semesterType";dics>
                                <#list dics as dic>
                                    <#if editEntity.type == dic.code>
                                        <option value="${dic.code}" selected="selected">${dic.value}</option>
                                    <#else>
                                        <option value="${dic.code}">${dic.value}</option>
                                    </#if>
                                </#list>
                            </@dictionary>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="col-xm-12 col-sm-12 col-lg-12">
                    <div class="form-group">
                        <label class="col-xm-2 col-sm-2 col-lg-2 col-sm-offset-2 control-label no-padding-right"><span style="color: red">*</span>学期日期：</label>
                        <div class="col-xm-3 col-sm-3 col-lg-3">
                                <span class="input-icon icon-left">
                                    <input data-bv-date-format="YYYY-MM-DD"
                                           name="startDate"  disabled="disabled" id="d4311"
                                           data-bv-message="日期已在设置学期之间！"
                                           value="${(editEntity.startDate???string(editEntity.startDate?string('yyyy-MM-dd'),''))!''}"
                                           class="form-control date-picker"
                                           required="required "
                                           alt="学期日期" onchange="inputTime(this)"
                                           placeholder="学期日期" type="text"
                                           onfocus="WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'d4312\')}'})"/>
                                    <i class="fa fa-calendar"></i>
                                </span>
                        </div>

                        <label class="col-xm-1 col-sm-1 col-lg-1" style="width: 30px;line-height: 30px;">-</label>
                        <div class="col-xm-3 col-sm-3 col-lg-3">
                                <span class="input-icon icon-left">
                                    <input style="width: 200px;height: 30px;border: 1px solid #c6d5d8;border-radius: 4px !important;"
                                           data-bv-date-format="YYYY-MM-DD"
                                           name="endDate" disabled="disabled" id="d4312"
                                           data-bv-message="日期已在设置学期之间！"
                                           value="${(editEntity.endDate???string(editEntity.endDate?string('yyyy-MM-dd'),''))!''}"
                                           class="form-control date-picker"
                                           required="required "
                                           alt="学期日期" onchange="inputTime(this)"
                                           placeholder="学期日期" type="text"
                                           onfocus="WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'d4311\')}'})" />
                                    <i class="fa fa-calendar"></i>
                                     <span class="text"></span>
                                </span>
                        </div>
                    </div>
                </div>

                <div class="col-sm-12">
                    <div class="text-align-center ">
                        <button style="min-width: 80px;margin-right:20px" id="editFormSubmitBtn_${serializeNum}" onclick="validateSemester()" type="submit" class="btn btn-blue">确定
                        </button>
                        <button style="width: 80px" type="button" class="btn btn-blue" data-dismiss="modal">取消
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
    $(".selectpicker_${serializeNum}").select2();

    //动态添加验证
    $("[name='startDate'],[name='endDate'],[name='type']").removeAttr("disabled");
    var formValidation = $('#editForm_${serializeNum}').data('bootstrapValidator');
    formValidation.addField("type",{
            validators:{
                remote:{
                    url:"tssSemesterController/queryByDateAndYear.do",
                    type: 'POST',
                    data: function(validator, $field, value) {
                        return {
                            id:"${editEntity.id}",
                            particularYear: validator.getFieldElements('particularYear').val(),
                            startDate: validator.getFieldElements('startDate').val(),
                            endDate: validator.getFieldElements('endDate').val(),
                            type: validator.getFieldElements('type').val()
                        };
                    }
                }
            }
        }).addField("startDate",{
       validators:{
            remote:{
                url:"tssSemesterController/queryByDateAndYear.do",
                type: 'POST',
                data: function(validator, $field, value) {
                    return {
                        id:"${editEntity.id}",
                        particularYear: validator.getFieldElements('particularYear').val(),
                        startDate: validator.getFieldElements('startDate').val(),
                        endDate: validator.getFieldElements('endDate').val(),
                        type: validator.getFieldElements('type').val()
                    };
                }
            }
        }
    }).addField("endDate",{
        validators:{
            remote:{
                url:"tssSemesterController/queryByDateAndYear.do",
                type: 'POST',
                data: function(validator, $field, value) {
                    return {
                        id:"${editEntity.id}",
                        particularYear: validator.getFieldElements('particularYear').val(),
                        startDate: validator.getFieldElements('startDate').val(),
                        endDate: validator.getFieldElements('endDate').val(),
                        type: validator.getFieldElements('type').val()
                    };
                }
            }
        }
    });



    /**
     * 年份
     * */
    $(function () {
        var data = $("#newParticularYear").attr("value");
        var arr = ['<option value="">请选择</option>'];
        for (var i = 2017; i <= 2037; i++) {
            if(i == data){
                arr.push('<option value="' + i + '" selected="selected">' + i + '</option>')
            } else {
                arr.push('<option value="' + i + '">' + i + '</option>')
            }
        }
        $("#newParticularYear").html(arr.join(''))
    });


    $("#newParticularYear").change(function () {
        $(this).attr("value",$(this).val());
    })

    function inputTime(that) {
        var name = that.name;
        var bootstrapValidator = $("#editForm_${serializeNum}").data('bootstrapValidator');
        bootstrapValidator.updateStatus(name, 'NOT_VALIDATED').validateField(name); //错误提示信息变了
    }

    $("#editForm_${serializeNum}").bind("ajaxSubmitCallback", function (event, result) {
        if (result.resCode == 200) {
            bootbox.hideAll();
            logger.info(result.resMsg, true);
            toView('tssSemesterController/tssSemesterList.do',true,'POST',{pageSize:10})
        } else {
            logger.error(result.resMsg);
        }
    });


</script>